package com.woniuxy.ams.controller;

import com.woniuxy.ams.entity.ResultEntity;
import com.woniuxy.ams.entity.User;
import com.woniuxy.ams.service.AuthService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fyx
 */
@RestController
public class AuthController {
    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    @PostMapping("/login")
    public ResultEntity<?> login(@RequestBody User user) {
        User subject = authService.login(user.getName(), user.getPassword());
        if (subject == null) {
            return new ResultEntity<>(401, "登录失败", null);
        }
        return new ResultEntity<>(200, "登录成功", subject);
    }
}
